package com.lyfei.yd.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lyfei.yd.mapper.SysUserRoleMapper;
import com.lyfei.yd.domain.entity.SysRole;
import com.lyfei.yd.domain.entity.SysUserRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("sysUserRoleService")
public class SysUserRoleService extends BaseService<SysUserRoleMapper, SysUserRole>{

    @Autowired
    private SysRoleService sysRoleService;

    public SysRole getRoleByUserId(Long userId){
        QueryWrapper<SysUserRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        SysUserRole userRole = this.getOne(queryWrapper);
        if(null != userRole){
            return sysRoleService.getById(userRole.getRoleId());
        }

        return null;
    }
}
